package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    OrdersService ordersService;

    @GetMapping("/userPage")
    public R<IPage<Orders>> selectPage(Integer page,Integer pageSize){

       IPage<Orders> pageNumber =  ordersService.selectPage(page,pageSize);

        return R.success(pageNumber);
    }

    /**
     * 确认订单页面，他在确认订单之前去查询了当前
     * 用户购物车的集合 然后将购物车里面的数据
     * 生成订单并提交
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
         ordersService.submit(orders);
        return R.success("save");
    }
}
